package com.cash.lemoloan.statisticlib.Utils;

import android.annotation.SuppressLint;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;


import com.cash.lemoloan.statisticlib.StatisticApplication;
import com.cash.lemoloan.statisticlib.model.StatisticPic01Info;

import java.util.ArrayList;
import java.util.List;


public class PicUtil {
    public synchronized static List<StatisticPic01Info> getPicInfo(){
        List<StatisticPic01Info> pic01InfoList = new ArrayList<>();
        Cursor cursor = null;
        try {
            Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            if(uri == null){
                return pic01InfoList;
            }

            cursor = StatisticApplication.getInstance()
                    .getContentResolver()
                    .query(uri, null, null, null, null);
            if(cursor == null){
                return pic01InfoList;
            }

            if(cursor.moveToFirst()){
                do {
                    @SuppressLint("Range") String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
                    @SuppressLint("Range") String createTime = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATE_ADDED));
                    StatisticPic01Info pic01Info = new StatisticPic01Info();
                    pic01Info.setCtime(String.valueOf(System.currentTimeMillis()));
                    pic01Info.setPicPath(path);
                    pic01Info.setPicCreateTime(createTime);
                    pic01InfoList.add(pic01Info);
                }while (cursor.moveToNext());
            }
        }catch (Exception e){

        }finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }catch (Exception e){}
            }
        }
        return pic01InfoList;
    }
}
